package com.xbongbong.pro.service.toolbox.statistic.help;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.PaasUserEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.elasticsearch.pojo.dto.InsertDTO;
import com.xbongbong.paas.enums.FlowStatusEnum;
import com.xbongbong.paas.help.FormDataHelp;
import com.xbongbong.paas.model.PaasCoUserModel;
import com.xbongbong.paas.model.PaasUserModel;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.constant.ElasticConstant;
import com.xbongbong.pro.enums.errorcodes.UserTeamErrorCodeEnum;
import com.xbongbong.pro.listbatch.pojo.TeamBatchPojo;
import com.xbongbong.saas.domain.entity.BomUserEntity;
import com.xbongbong.saas.domain.entity.CallCenterCallLogEntity;
import com.xbongbong.saas.domain.entity.ClueUserEntity;
import com.xbongbong.saas.domain.entity.CommunicatePlanUserEntity;
import com.xbongbong.saas.domain.entity.ContactUserEntity;
import com.xbongbong.saas.domain.entity.ContractPerformanceEntity;
import com.xbongbong.saas.domain.entity.ContractProductEntity;
import com.xbongbong.saas.domain.entity.ContractUserEntity;
import com.xbongbong.saas.domain.entity.CustomerUserEntity;
import com.xbongbong.saas.domain.entity.DistributorAccountEntity;
import com.xbongbong.saas.domain.entity.FundAccountFlowEntity;
import com.xbongbong.saas.domain.entity.MarketActivityUserEntity;
import com.xbongbong.saas.domain.entity.OpportunityUserEntity;
import com.xbongbong.saas.domain.entity.PayBalanceEntity;
import com.xbongbong.saas.domain.entity.PayBalanceUserEntity;
import com.xbongbong.saas.domain.entity.PayPlanSheetUserEntity;
import com.xbongbong.saas.domain.entity.PayPlanUserEntity;
import com.xbongbong.saas.domain.entity.PaymentBalanceEntity;
import com.xbongbong.saas.domain.entity.PaymentBalanceUserEntity;
import com.xbongbong.saas.domain.entity.PaymentSheetUserEntity;
import com.xbongbong.saas.domain.entity.PaymentTaskUserEntity;
import com.xbongbong.saas.domain.entity.PaymentUserEntity;
import com.xbongbong.saas.domain.entity.ProductStockEntity;
import com.xbongbong.saas.domain.entity.ProductUserEntity;
import com.xbongbong.saas.domain.entity.ProductWarehouseEntity;
import com.xbongbong.saas.domain.entity.ProductionOrderUserEntity;
import com.xbongbong.saas.domain.entity.PurchaseUserEntity;
import com.xbongbong.saas.domain.entity.QuotationUserEntity;
import com.xbongbong.saas.domain.entity.RefundUserEntity;
import com.xbongbong.saas.domain.entity.StaticForMarketActivityEntity;
import com.xbongbong.saas.domain.entity.SupplierContactUserEntity;
import com.xbongbong.saas.domain.entity.SupplierUserEntity;
import com.xbongbong.saas.domain.entity.WarehouseUserEntity;
import com.xbongbong.saas.domain.entity.WorkOrderCcEntity;
import com.xbongbong.saas.domain.entity.WorkOrderEvaluateEntity;
import com.xbongbong.saas.domain.entity.WorkOrderFlowUserEntity;
import com.xbongbong.saas.enums.UserTeamOperateTagEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.model.BomUserModel;
import com.xbongbong.saas.model.CallCenterCallLogModel;
import com.xbongbong.saas.model.ClueUserModel;
import com.xbongbong.saas.model.CommunicatePlanUserModel;
import com.xbongbong.saas.model.CompetitorUserModel;
import com.xbongbong.saas.model.ContactUserModel;
import com.xbongbong.saas.model.ContractPerformanceModel;
import com.xbongbong.saas.model.ContractProductModel;
import com.xbongbong.saas.model.ContractUserModel;
import com.xbongbong.saas.model.CustomerUserModel;
import com.xbongbong.saas.model.DistributorAccountModel;
import com.xbongbong.saas.model.FundAccountFlowModel;
import com.xbongbong.saas.model.MarketActivityForStaticModel;
import com.xbongbong.saas.model.MarketActivityUserModel;
import com.xbongbong.saas.model.OpportunityUserModel;
import com.xbongbong.saas.model.PayBalanceModel;
import com.xbongbong.saas.model.PayBalanceUserModel;
import com.xbongbong.saas.model.PayPlanSheetUserModel;
import com.xbongbong.saas.model.PayPlanUserModel;
import com.xbongbong.saas.model.PaymentBalanceModel;
import com.xbongbong.saas.model.PaymentBalanceUserModel;
import com.xbongbong.saas.model.PaymentSheetUserModel;
import com.xbongbong.saas.model.PaymentTaskUserModel;
import com.xbongbong.saas.model.PaymentUserModel;
import com.xbongbong.saas.model.ProductStockModel;
import com.xbongbong.saas.model.ProductUserModel;
import com.xbongbong.saas.model.ProductWarehouseModel;
import com.xbongbong.saas.model.ProductionOrderUserModel;
import com.xbongbong.saas.model.PurchaseUserModel;
import com.xbongbong.saas.model.QuotationUserModel;
import com.xbongbong.saas.model.RefundUserModel;
import com.xbongbong.saas.model.SupplierContactUserModel;
import com.xbongbong.saas.model.SupplierUserModel;
import com.xbongbong.saas.model.WarehouseUserModel;
import com.xbongbong.saas.model.WorkOrderCcModel;
import com.xbongbong.saas.model.WorkOrderEvaluateModel;
import com.xbongbong.saas.model.WorkOrderFlowUserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author 梁鲁江
 * @version v1.0
 * @date 2019/5/5 16:30
 * @since v1.0
 */
@Component
public class TeamHelp {

    @Resource
    private MarketActivityForStaticModel marketActivityForStaticModel;
    @Resource
    private CallCenterCallLogModel callCenterCallLogModel;
    @Resource
    private CustomerUserModel customerUserModel;
    @Resource
    private ContractPerformanceModel contractPerformanceModel;
    @Resource
    private BomUserModel bomUserModel;
    @Resource
    private ContactUserModel contactUserModel;
    @Resource
    private ContractUserModel contractUserModel;
    @Resource
    private CommunicatePlanUserModel communicatePlanUserModel;
    @Resource
    private OpportunityUserModel opportunityUserModel;
    @Resource
    private PayPlanUserModel payPlanUserModel;
    @Resource
    private PaymentUserModel paymentUserModel;
    @Resource
    private ProductUserModel productUserModel;
    @Resource
    private ProductionOrderUserModel productionOrderUserModel;
    @Resource
    private WorkOrderFlowUserModel workOrderFlowUserModel;
    @Resource
    private PurchaseUserModel purchaseUserModel;
    @Resource
    private RefundUserModel refundUserModel;
    @Resource
    private SupplierContactUserModel supplierContactUserModel;
    @Resource
    private SupplierUserModel supplierUserModel;
    @Resource
    private WarehouseUserModel warehouseUserModel;
    @Resource
    private ProductWarehouseModel productWarehouseModel;
    @Resource
    private ProductStockModel productStockModel;
    @Resource
    private WorkOrderCcModel workOrderCcModel;
    @Resource
    private WorkOrderEvaluateModel workOrderEvaluateModel;
    @Resource
    private ContractProductModel contractProductModel;
    @Resource
    private QuotationUserModel quotationUserModel;
    @Resource
    private PaymentBalanceUserModel paymentBalanceUserModel;
    @Resource
    private PaymentBalanceModel paymentBalanceModel;
    @Resource
    private PayBalanceUserModel payBalanceUserModel;
    @Resource
    private PayBalanceModel payBalanceModel;
    @Resource
    private FundAccountFlowModel fundAccountFlowModel;
    @Resource
    private PaymentSheetUserModel paymentSheetUserModel;
    @Resource
    private PayPlanSheetUserModel payPlanSheetUserModel;
    @Resource
    private PaymentTaskUserModel paymentTaskUserModel;
    @Resource
    private DistributorAccountModel distributorAccountModel;
    @Resource
    private MarketActivityUserModel marketActivityUserModel;
    @Resource
    private ClueUserModel clueUserModel;
    @Resource
    private PaasCoUserModel paasCoUserModel;
    @Resource
    private PaasUserModel paasUserModel;
    @Resource
    private CompetitorUserModel competitorUserModel;
    @Resource
    private FormDataHelp formDataHelp;



    private static final Logger LOG = LoggerFactory.getLogger(TeamHelp.class);
    /**
     * 获取数据
     * @param xbbRefTypeEnum
     * @param params
     * @param list
     * @return
     */
    public List getList(XbbRefTypeEnum xbbRefTypeEnum, Map<String, Object> params, List list) {
        switch (xbbRefTypeEnum) {
            case MARKET_ACTIVITY_STATIC:
                list = marketActivityForStaticModel.findEntitys(params);
                break;
            case CALL_CENTER_CALL_LOG:
                list = callCenterCallLogModel.findEntitys(params);
                break;
            case CUSTOMER_TEAM:
                list = customerUserModel.findEntitys(params);
                break;
            case CONTRACT_PERFORMANCE:
                list = contractPerformanceModel.findEntitys(params);
                break;
            case BOM_BILL_TEAM:
                list = bomUserModel.findEntitys(params);
                break;
            case COMMUNICATE_PLAN_TEAM:
                list = communicatePlanUserModel.findEntitys(params);
                break;
            case CONTACT_TEAM:
                list = contactUserModel.findEntityOriginal(params);
                break;
            case CONTRACT_TEAM:
                list = contractUserModel.findEntitys(params);
                break;
            case SALES_OPPORTUNITY_TEAM:
                list = opportunityUserModel.findEntitys(params);
                break;
            case PAY_PLAN_TEAM:
                list = payPlanUserModel.findEntitys(params);
                break;
            case PAYMENT_TEAM:
                list = paymentUserModel.findEntitys(params);
                break;
            case PRODUCT_TEAM:
                list = productUserModel.findEntitys(params);
                break;
            case PRODUCTION_ORDER_TEAM:
                list = productionOrderUserModel.findEntitys(params);
                break;
            case WORK_ORDER_TEAM:
                list = workOrderFlowUserModel.findEntitys(params);
                break;
            case PURCHASE_TEAM:
                list = purchaseUserModel.findEntitys(params);
                break;
            case REFUND_TEAM:
                list = refundUserModel.findEntitys(params);
                break;
            case SUPPLIER_CONTACT_TEAM:
                list = supplierContactUserModel.findEntitys(params);
                break;
            case SUPPLIER_TEAM:
                list = supplierUserModel.findEntitys(params);
                break;
            case WAREHOUSE_TEAM:
                list = warehouseUserModel.findEntitys(params);
                break;
            case PRODUCT_WAREHOUSE:
                list = productWarehouseModel.findEntitysWithWarehouseChecked(params,null);
                break;
            case PRODUCT_STOCK_INFO:
                list = productStockModel.findEntitys(params);
                break;
            case WORK_ORDER_CC:
                list = workOrderCcModel.findEntitys(params);
                break;
            case WORK_ORDER_EVALUATION:
                list = workOrderEvaluateModel.findEntitys(params);
                break;
            case CONTRACT_PRODUCT:
                list = contractProductModel.findEntitys(params);
                break;
            case QUOTATION_TEAM:
                list = quotationUserModel.findEntitys(params);
                break;
            case PREPAYMENT_BALANCE:
                list =paymentBalanceModel .findEntitys(params);
                break;
            case PREPAYMENT_BALANCE_TEAM:
                list = paymentBalanceUserModel.findEntitys(params);
                break;
            case PREPAY_BALANCE:
                list =payBalanceModel.findEntitys(params);
                break;
            case PREPAY_BALANCE_TEAM:
                list = payBalanceUserModel.findEntitys(params);
                break;
            case FUND_ACCOUNT_FLOW:
                list = fundAccountFlowModel.findEntitys(params);
                break;
            case PAYMENT_SHEET_TEAM:
                list = paymentSheetUserModel.findEntitys(params);
                break;
            case PAY_SHEET_TEAM:
                list = payPlanSheetUserModel.findEntitys(params);
                break;
            case MARKET_ACTIVITY_TEAM:
                list = marketActivityUserModel.findEntitys(params);
                break;
            case CLUE_TEAM:
                list = clueUserModel.findEntitys(params);
                break;
            case PAYMENT_TASK_TEAM:
                list = paymentTaskUserModel.findEntitys(params);
                break;
            case DISTRIBUTOR_ACCOUNT:
                list = distributorAccountModel.findEntitys(params);
                break;
            case PAAS_TEAM:
                list = paasUserModel.findEntitys(params);
                break;
            case COMPETITOR_TEAM:
                list = competitorUserModel.findEntitys(params);
                break;
            default:
                break;
        }
        return list;
    }
    public Integer getEntitysCount(XbbRefTypeEnum xbbRefTypeEnum, Map<String, Object> params) {
        IModel iModel = null;
        switch (xbbRefTypeEnum) {
            case CALL_CENTER_CALL_LOG:
                iModel = callCenterCallLogModel;
                break;
            case CUSTOMER_TEAM:
                iModel = customerUserModel;
                break;
            case CONTRACT_PERFORMANCE:
                iModel = contractPerformanceModel;
                break;
            case BOM_BILL_TEAM:
                iModel = bomUserModel;
                break;
            case COMMUNICATE_PLAN_TEAM:
                iModel = communicatePlanUserModel;
                break;
            case CONTACT_TEAM:
                iModel = contactUserModel;
                break;
            case CONTRACT_TEAM:
                iModel = contractUserModel;
                break;
            case SALES_OPPORTUNITY_TEAM:
                iModel = opportunityUserModel;
                break;
            case PAY_PLAN_TEAM:
                iModel = payPlanUserModel;
                break;
            case PAYMENT_TEAM:
                iModel = paymentUserModel;
                break;
            case PRODUCT_TEAM:
                iModel = productUserModel;
                break;
            case PRODUCTION_ORDER_TEAM:
                iModel = productionOrderUserModel;
                break;
            case WORK_ORDER_TEAM:
                iModel = workOrderFlowUserModel;
                break;
            case PURCHASE_TEAM:
                iModel = purchaseUserModel;
                break;
            case REFUND_TEAM:
                iModel = refundUserModel;
                break;
            case SUPPLIER_CONTACT_TEAM:
                iModel = supplierContactUserModel;
                break;
            case SUPPLIER_TEAM:
                iModel = supplierUserModel;
                break;
            case WAREHOUSE_TEAM:
                iModel = warehouseUserModel;
                break;
            case PRODUCT_WAREHOUSE:
                return productWarehouseModel.getEntitysCount(params);
            case PRODUCT_STOCK_INFO:
                iModel = productStockModel;
                break;
            case WORK_ORDER_CC:
                iModel = workOrderCcModel;
                break;
            case WORK_ORDER_EVALUATION:
                iModel = workOrderEvaluateModel;
                break;
            case CONTRACT_PRODUCT:
                iModel = contractProductModel;
                break;
            case QUOTATION_TEAM:
                iModel = quotationUserModel;
                break;
            case PREPAYMENT_BALANCE:
                iModel =paymentBalanceModel ;
                break;
            case PREPAYMENT_BALANCE_TEAM:
                iModel = paymentBalanceUserModel;
                break;
            case PREPAY_BALANCE:
                iModel =payBalanceModel;
                break;
            case PREPAY_BALANCE_TEAM:
                iModel = payBalanceUserModel;
                break;
            case FUND_ACCOUNT_FLOW:
                iModel = fundAccountFlowModel;
                break;
            case PAYMENT_SHEET_TEAM:
                iModel = paymentSheetUserModel;
                break;
            case PAY_SHEET_TEAM:
                iModel = payPlanSheetUserModel;
                break;
            default:
                LOG.info("==default==="+xbbRefTypeEnum);
                return 0;
        }
        return iModel.getEntitysCount(params);
    }

    /**
     * 设置大于上次的节点
     * @param xbbRefTypeEnum
     * @param params
     * @param list
     */
    public void setIdGte(XbbRefTypeEnum xbbRefTypeEnum, Map<String, Object> params, List list) {
        Object o = list.get(list.size() - 1);
        switch (xbbRefTypeEnum) {
            case MARKET_ACTIVITY_STATIC:
                StaticForMarketActivityEntity staticForMarketActivity = (StaticForMarketActivityEntity) o;
                params.put("idGte", staticForMarketActivity.getId());
                break;
            case CALL_CENTER_CALL_LOG:
                CallCenterCallLogEntity callCenterCallLogEntity = (CallCenterCallLogEntity) o;
                params.put("idGte", callCenterCallLogEntity.getId());
                break;
            case CUSTOMER_TEAM:
                CustomerUserEntity customerUserEntity = (CustomerUserEntity) o;
                params.put("idGte", customerUserEntity.getId());
                break;
            case CONTRACT_PERFORMANCE:
                ContractPerformanceEntity contractPerformanceEntity = (ContractPerformanceEntity) o;
                params.put("idGte", contractPerformanceEntity.getId());
                break;
            case COMMUNICATE_PLAN_TEAM:
                CommunicatePlanUserEntity communicatePlanUserEntity = (CommunicatePlanUserEntity) o;
                params.put("idGte", communicatePlanUserEntity.getId());
                break;
            case CONTACT_TEAM:
                ContactUserEntity contactUserEntity = (ContactUserEntity) o;
                params.put("idGte", contactUserEntity.getId());
                break;
            case CONTRACT_TEAM:
                ContractUserEntity contractUserEntity = (ContractUserEntity) o;
                params.put("idGte", contractUserEntity.getId());
                break;
            case SALES_OPPORTUNITY_TEAM:
                OpportunityUserEntity opportunityUserEntity = (OpportunityUserEntity) o;
                params.put("idGte", opportunityUserEntity.getId());
                break;
            case PAY_PLAN_TEAM:
                PayPlanUserEntity payPlanUserEntity = (PayPlanUserEntity) o;
                params.put("idGte", payPlanUserEntity.getId());
                break;
            case PAYMENT_TEAM:
                PaymentUserEntity paymentUserEntity = (PaymentUserEntity) o;
                params.put("idGte", paymentUserEntity.getId());
                break;
            case PRODUCT_TEAM:
                ProductUserEntity productUserEntity = (ProductUserEntity) o;
                params.put("idGte", productUserEntity.getId());
                break;
            case PRODUCTION_ORDER_TEAM:
                ProductionOrderUserEntity productionOrderUserEntity = (ProductionOrderUserEntity) o;
                params.put("idGte", productionOrderUserEntity.getId());
                break;
            case WORK_ORDER_TEAM:
                WorkOrderFlowUserEntity workOrderFlowUserEntity = (WorkOrderFlowUserEntity) o;
                params.put("idGte", workOrderFlowUserEntity.getId());
                break;
            case PURCHASE_TEAM:
                PurchaseUserEntity purchaseUserEntity = (PurchaseUserEntity) o;
                params.put("idGte", purchaseUserEntity.getId());
                break;
            case REFUND_TEAM:
                RefundUserEntity refundUserEntity = (RefundUserEntity) o;
                params.put("idGte", refundUserEntity.getId());
                break;
            case SUPPLIER_CONTACT_TEAM:
                SupplierContactUserEntity supplierContactUserEntity = (SupplierContactUserEntity) o;
                params.put("idGte", supplierContactUserEntity.getId());
                break;
            case SUPPLIER_TEAM:
                SupplierUserEntity supplierUserEntity = (SupplierUserEntity) o;
                params.put("idGte", supplierUserEntity.getId());
                break;
            case WAREHOUSE_TEAM:
                WarehouseUserEntity warehouseUserEntity = (WarehouseUserEntity) o;
                params.put("idGte", warehouseUserEntity.getId());
                break;
            case BOM_BILL_TEAM:
                BomUserEntity bomUserEntity = (BomUserEntity) o;
                params.put("idGte", bomUserEntity.getId());
                break;
            case PRODUCT_WAREHOUSE:
                ProductWarehouseEntity productWarehouseEntity = (ProductWarehouseEntity) o;
                params.put("idGte", productWarehouseEntity.getId());
                break;
            case PRODUCT_STOCK_INFO:
                ProductStockEntity productStockEntity = (ProductStockEntity) o;
                params.put("idGte", productStockEntity.getId());
                break;
            case WORK_ORDER_CC:
                WorkOrderCcEntity workOrderCcEntity = (WorkOrderCcEntity) o;
                params.put("idGte", workOrderCcEntity.getId());
                break;
            case WORK_ORDER_EVALUATION:
                WorkOrderEvaluateEntity workOrderEvaluateEntity = (WorkOrderEvaluateEntity) o;
                params.put("idGte", workOrderEvaluateEntity.getId());
                break;
            case CONTRACT_PRODUCT:
                ContractProductEntity contractProductEntity = (ContractProductEntity) o;
                params.put("idGte", contractProductEntity.getId());
                break;
            case QUOTATION_TEAM:
                QuotationUserEntity quotationUserEntity = (QuotationUserEntity) o;
                params.put("idGte", quotationUserEntity.getId());
                break;
            case PREPAYMENT_BALANCE:
                PaymentBalanceEntity paymentBalanceEntity = (PaymentBalanceEntity) o;
                params.put("idGte", paymentBalanceEntity.getId());
                break;
            case PREPAYMENT_BALANCE_TEAM:
                PaymentBalanceUserEntity paymentBalanceUserEntity = (PaymentBalanceUserEntity) o;
                params.put("idGte", paymentBalanceUserEntity.getId());
                break;
            case PREPAY_BALANCE:
                PayBalanceEntity payBalanceEntity = (PayBalanceEntity) o;
                params.put("idGte", payBalanceEntity.getId());
                break;
            case PREPAY_BALANCE_TEAM:
                PayBalanceUserEntity payBalanceUserEntity = (PayBalanceUserEntity) o;
                params.put("idGte", payBalanceUserEntity.getId());
                break;
            case FUND_ACCOUNT_FLOW:
                FundAccountFlowEntity fundAccountFlowEntity = (FundAccountFlowEntity) o;
                params.put("idGte", fundAccountFlowEntity.getId());
                break;
            case PAYMENT_SHEET_TEAM:
                PaymentSheetUserEntity paymentSheetUserEntity = (PaymentSheetUserEntity) o;
                params.put("idGte", paymentSheetUserEntity.getId());
                break;
            case PAY_SHEET_TEAM:
                PayPlanSheetUserEntity payPlanSheetUserEntity = (PayPlanSheetUserEntity) o;
                params.put("idGte", payPlanSheetUserEntity.getId());
                break;
            case MARKET_ACTIVITY_TEAM:
                MarketActivityUserEntity marketActivityUserEntity = (MarketActivityUserEntity) o;
                params.put("idGte", marketActivityUserEntity.getId());
                break;
            case CLUE_TEAM:
                ClueUserEntity clueUserEntity = (ClueUserEntity) o;
                params.put("idGte", clueUserEntity.getId());
                break;
            case DISTRIBUTOR_ACCOUNT:
                DistributorAccountEntity distributorAccountEntity = (DistributorAccountEntity) o;
                params.put("idGte", distributorAccountEntity.getId());
                break;
            case PAAS_TEAM:
                PaasUserEntity paasUserEntity = (PaasUserEntity) o;
                params.put("idGte", paasUserEntity.getId());
                break;
            default:
                break;
        }
    }

    /**
     * 设置插入的标转化数据
     * @param xbbRefTypeEnum
     * @param object   数据实体
     * @param insertDTO
     * @throws XbbException
     */
    public void setInsertDTO(XbbRefTypeEnum xbbRefTypeEnum, Object object, InsertDTO insertDTO) throws XbbException {
        switch (xbbRefTypeEnum) {
            case MARKET_ACTIVITY_STATIC:
                StaticForMarketActivityEntity staticForMarketActivity = (StaticForMarketActivityEntity) object;
                insertDTO.setEsId(staticForMarketActivity.getCorpid() + "_" + staticForMarketActivity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(staticForMarketActivity, false, true));
                break;
            case CALL_CENTER_CALL_LOG:
                CallCenterCallLogEntity callCenterCallLogEntity = (CallCenterCallLogEntity) object;
                insertDTO.setEsId(callCenterCallLogEntity.getCorpid() + "_" + callCenterCallLogEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(callCenterCallLogEntity, false, true));
                break;
            case CUSTOMER_TEAM:
                CustomerUserEntity customerUserEntity = (CustomerUserEntity) object;
                insertDTO.setEsId(customerUserEntity.getCorpid() + "_" + customerUserEntity.getId());
                Map<String, Object> source = BeanUtil.convertBean2Map(customerUserEntity, false, true);
                String parent = customerUserEntity.getCorpid() + "_" + customerUserEntity.getDataId();
                String relations = "{\"name\":\"" + insertDTO.getIndexTypeEnum().getType() + "\",\"parent\":\"" + parent  +"\"}";
                source.put(ElasticConstant.MY_JOIN_FIELD,  (JSONObject) JSONObject.parse(relations));
                insertDTO.setSource(source);
                insertDTO.setParent(parent);
                break;
            case CONTRACT_PERFORMANCE:
                ContractPerformanceEntity contractPerformanceEntity = (ContractPerformanceEntity) object;
                insertDTO.setEsId(contractPerformanceEntity.getCorpid() + "_" + contractPerformanceEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(contractPerformanceEntity, false, true));
                insertDTO.setParent(contractPerformanceEntity.getCorpid() + "_" + contractPerformanceEntity.getContractId());
                break;
            case COMMUNICATE_PLAN_TEAM:
                CommunicatePlanUserEntity communicatePlanUserEntity = (CommunicatePlanUserEntity) object;
                insertDTO.setEsId(communicatePlanUserEntity.getCorpid() + "_" + communicatePlanUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(communicatePlanUserEntity, false, true));
                insertDTO.setParent(communicatePlanUserEntity.getCorpid() + "_" + communicatePlanUserEntity.getDataId());
                break;
            case CONTACT_TEAM:
                ContactUserEntity contactUserEntity = (ContactUserEntity) object;
                insertDTO.setEsId(contactUserEntity.getCorpid() + "_" + contactUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(contactUserEntity, false, true));
                insertDTO.setParent(contactUserEntity.getCorpid() + "_" + contactUserEntity.getDataId());
                break;
            case CONTRACT_TEAM:
                ContractUserEntity contractUserEntity = (ContractUserEntity) object;
                insertDTO.setEsId(contractUserEntity.getCorpid() + "_" + contractUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(contractUserEntity, false, true));
                insertDTO.setParent(contractUserEntity.getCorpid() + "_" + contractUserEntity.getDataId());
                break;
            case SALES_OPPORTUNITY_TEAM:
                OpportunityUserEntity opportunityUserEntity = (OpportunityUserEntity) object;
                insertDTO.setEsId(opportunityUserEntity.getCorpid() + "_" + opportunityUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(opportunityUserEntity, false, true));
                insertDTO.setParent(opportunityUserEntity.getCorpid() + "_" + opportunityUserEntity.getDataId());
                break;
            case PAY_PLAN_TEAM:
                PayPlanUserEntity payPlanUserEntity = (PayPlanUserEntity) object;
                insertDTO.setEsId(payPlanUserEntity.getCorpid() + "_" + payPlanUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(payPlanUserEntity, false, true));
                insertDTO.setParent(payPlanUserEntity.getCorpid() + "_" + payPlanUserEntity.getDataId());
                break;
            case PAYMENT_TEAM:
                PaymentUserEntity paymentUserEntity = (PaymentUserEntity) object;
                insertDTO.setEsId(paymentUserEntity.getCorpid() + "_" + paymentUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(paymentUserEntity, false, true));
                insertDTO.setParent(paymentUserEntity.getCorpid() + "_" + paymentUserEntity.getDataId());
                break;
            case PRODUCT_TEAM:
                ProductUserEntity productUserEntity = (ProductUserEntity) object;
                insertDTO.setEsId(productUserEntity.getCorpid() + "_" + productUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(productUserEntity, false, true));
                insertDTO.setParent(productUserEntity.getCorpid() + "_" + productUserEntity.getDataId());
                break;
            case PRODUCTION_ORDER_TEAM:
                ProductionOrderUserEntity productionOrderUserEntity = (ProductionOrderUserEntity) object;
                insertDTO.setEsId(productionOrderUserEntity.getCorpid() + "_" + productionOrderUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(productionOrderUserEntity, false, true));
                insertDTO.setParent(productionOrderUserEntity.getCorpid() + "_" + productionOrderUserEntity.getDataId());
                break;
            case WORK_ORDER_TEAM:
                WorkOrderFlowUserEntity workOrderFlowUserEntity = (WorkOrderFlowUserEntity) object;
                insertDTO.setEsId(workOrderFlowUserEntity.getCorpid() + "_" + workOrderFlowUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(workOrderFlowUserEntity, false, true));
                insertDTO.setParent(workOrderFlowUserEntity.getCorpid() + "_" + workOrderFlowUserEntity.getDataId());
                break;
            case PURCHASE_TEAM:
                PurchaseUserEntity purchaseUserEntity = (PurchaseUserEntity) object;
                insertDTO.setEsId(purchaseUserEntity.getCorpid() + "_" + purchaseUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(purchaseUserEntity, false, true));
                insertDTO.setParent(purchaseUserEntity.getCorpid() + "_" + purchaseUserEntity.getDataId());
                break;
            case REFUND_TEAM:
                RefundUserEntity refundUserEntity = (RefundUserEntity) object;
                insertDTO.setEsId(refundUserEntity.getCorpid() + "_" + refundUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(refundUserEntity, false, true));
                insertDTO.setParent(refundUserEntity.getCorpid() + "_" + refundUserEntity.getDataId());
                break;
            case SUPPLIER_CONTACT_TEAM:
                SupplierContactUserEntity supplierContactUserEntity = (SupplierContactUserEntity) object;
                insertDTO.setEsId(supplierContactUserEntity.getCorpid() + "_" + supplierContactUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(supplierContactUserEntity, false, true));
                insertDTO.setParent(supplierContactUserEntity.getCorpid() + "_" + supplierContactUserEntity.getDataId());
                break;
            case SUPPLIER_TEAM:
                SupplierUserEntity supplierUserEntity = (SupplierUserEntity) object;
                insertDTO.setEsId(supplierUserEntity.getCorpid() + "_" + supplierUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(supplierUserEntity, false, true));
                insertDTO.setParent(supplierUserEntity.getCorpid() + "_" + supplierUserEntity.getDataId());
                break;
            case WAREHOUSE_TEAM:
                WarehouseUserEntity warehouseUserEntity = (WarehouseUserEntity) object;
                insertDTO.setEsId(warehouseUserEntity.getCorpid() + "_" + warehouseUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(warehouseUserEntity, false, true));
                insertDTO.setParent(warehouseUserEntity.getCorpid() + "_" + warehouseUserEntity.getDataId());
                break;
            case BOM_BILL_TEAM:
                BomUserEntity bomUserEntity = (BomUserEntity) object;
                insertDTO.setEsId(bomUserEntity.getCorpid() + "_" + bomUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(bomUserEntity, false, true));
                insertDTO.setParent(bomUserEntity.getCorpid() + "_" + bomUserEntity.getDataId());
                break;
            case PRODUCT_WAREHOUSE:
                ProductWarehouseEntity productWarehouseEntity = (ProductWarehouseEntity) object;
                insertDTO.setEsId(productWarehouseEntity.getCorpid() + "_" + productWarehouseEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(productWarehouseEntity, false, true));
                insertDTO.setParent(productWarehouseEntity.getCorpid() + "_" + productWarehouseEntity.getProductId());
                break;
            case PRODUCT_STOCK_INFO:
                ProductStockEntity productStockEntity = (ProductStockEntity) object;
                insertDTO.setEsId(productStockEntity.getCorpid() + "_" + productStockEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(productStockEntity, false, true));
                insertDTO.setParent(productStockEntity.getCorpid() + "_" + productStockEntity.getProductId());
                break;
            case WORK_ORDER_CC:
                WorkOrderCcEntity workOrderCcEntity = (WorkOrderCcEntity) object;
                insertDTO.setEsId(workOrderCcEntity.getCorpid() + "_" + workOrderCcEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(workOrderCcEntity, false, true));
                insertDTO.setParent(workOrderCcEntity.getCorpid() + "_" + workOrderCcEntity.getWorkOrderId());
                break;
            case WORK_ORDER_EVALUATION:
                WorkOrderEvaluateEntity workOrderEvaluateEntity = (WorkOrderEvaluateEntity) object;
                insertDTO.setEsId(workOrderEvaluateEntity.getCorpid() + "_" + workOrderEvaluateEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(workOrderEvaluateEntity, false, true));
                insertDTO.setParent(workOrderEvaluateEntity.getCorpid() + "_" + workOrderEvaluateEntity.getWorkOrderId());
                break;
            case CONTRACT_PRODUCT:
                ContractProductEntity contractProductEntity = (ContractProductEntity) object;
                insertDTO.setEsId(contractProductEntity.getCorpid() + "_" + contractProductEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(contractProductEntity, false, true));
                insertDTO.getSource().remove("data");
                insertDTO.setParent(contractProductEntity.getCorpid() + "_" + contractProductEntity.getContractId());
                break;
            case PREPAYMENT_BALANCE:
                PaymentBalanceEntity paymentBalanceEntity = (PaymentBalanceEntity) object;
                insertDTO.setEsId(paymentBalanceEntity.getCorpid() + "_" + paymentBalanceEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(paymentBalanceEntity, false, true));
                break;
            case PREPAYMENT_BALANCE_TEAM:
                PaymentBalanceUserEntity paymentBalanceUserEntity = (PaymentBalanceUserEntity) object;
                insertDTO.setEsId(paymentBalanceUserEntity.getCorpid() + "_" + paymentBalanceUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(paymentBalanceUserEntity, false, true));
                insertDTO.setParent(paymentBalanceUserEntity.getCorpid() + "_" + paymentBalanceUserEntity.getDataId());
                break;
            case PREPAY_BALANCE:
                PayBalanceEntity payBalanceEntity = (PayBalanceEntity) object;
                insertDTO.setEsId(payBalanceEntity.getCorpid() + "_" + payBalanceEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(payBalanceEntity, false, true));
                break;
            case PREPAY_BALANCE_TEAM:
                PayBalanceUserEntity payBalanceUserEntity = (PayBalanceUserEntity) object;
                insertDTO.setEsId(payBalanceUserEntity.getCorpid() + "_" + payBalanceUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(payBalanceUserEntity, false, true));
                insertDTO.setParent(payBalanceUserEntity.getCorpid() + "_" + payBalanceUserEntity.getDataId());
                break;
            case FUND_ACCOUNT_FLOW:
                FundAccountFlowEntity fundAccountFlowEntity = (FundAccountFlowEntity) object;
                insertDTO.setEsId(fundAccountFlowEntity.getCorpid() + "_" + fundAccountFlowEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(fundAccountFlowEntity, false, true));
                break;
            case PAYMENT_SHEET_TEAM:
                PaymentSheetUserEntity paymentSheetUserEntity = (PaymentSheetUserEntity) object;
                insertDTO.setEsId(paymentSheetUserEntity.getCorpid() + "_" + paymentSheetUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(paymentSheetUserEntity, false, true));
                insertDTO.setParent(paymentSheetUserEntity.getCorpid() + "_" + paymentSheetUserEntity.getDataId());
                break;
            case PAY_SHEET_TEAM:
                PayPlanSheetUserEntity payPlanSheetUserEntity = (PayPlanSheetUserEntity) object;
                insertDTO.setEsId(payPlanSheetUserEntity.getCorpid() + "_" + payPlanSheetUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(payPlanSheetUserEntity, false, true));
                insertDTO.setParent(payPlanSheetUserEntity.getCorpid() + "_" + payPlanSheetUserEntity.getDataId());
                break;
            case MARKET_ACTIVITY_TEAM:
                MarketActivityUserEntity marketActivityUserEntity = (MarketActivityUserEntity) object;
                insertDTO.setEsId(marketActivityUserEntity.getCorpid() + "_" + marketActivityUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(marketActivityUserEntity, false, true));
                insertDTO.setParent(marketActivityUserEntity.getCorpid() + "_" + marketActivityUserEntity.getDataId());
                break;
            case CLUE_TEAM:
                ClueUserEntity elueUserEntity = (ClueUserEntity) object;
                insertDTO.setEsId(elueUserEntity.getCorpid() + "_" + elueUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(elueUserEntity, false, true));
                insertDTO.setParent(elueUserEntity.getCorpid() + "_" + elueUserEntity.getDataId());
                break;

            case PAYMENT_TASK_TEAM:
                PaymentTaskUserEntity paymentTaskUserEntity = (PaymentTaskUserEntity) object;
                insertDTO.setEsId(paymentTaskUserEntity.getCorpid() + "_" + paymentTaskUserEntity.getId());
                insertDTO.setSource(BeanUtil.convertBean2Map(paymentTaskUserEntity, false, true));
                insertDTO.setParent(paymentTaskUserEntity.getCorpid() + "_" + paymentTaskUserEntity.getDataId());
                break;
            default:
                break;
        }
    }

    /**
     * Description: 校验数据是否在审批中
     * @param dataIds
	 * @param corpid
	 * @param formId
	 * @param saasMark
	 * @param businessType
     * @return java.util.List<com.xbongbong.pro.listbatch.pojo.TeamBatchPojo>
     * @throws
     * @author 魏荣杰
     * @date 2023/1/9 10:38
     * @since
     */
    public List<TeamBatchPojo> checkDataIsApproval(List<Long> dataIds, String corpid, Long formId, Integer saasMark, Integer businessType, UserTeamOperateTagEnum userTeamOperateTagEnum) {
        List<PaasFormDataEntityExt> paasFormDataEntityExts = formDataHelp.getByDataIdList(dataIds, businessType, saasMark, formId, corpid);

        List<Integer> inApproval = Arrays.asList(FlowStatusEnum.APPROVAL_PENDING.getType(), FlowStatusEnum.IN_APPROVAL.getType());
        return paasFormDataEntityExts.stream().filter(v -> inApproval.contains(v.getFlowStatus())).map(v -> {
            // 在审批中的数据移除
            dataIds.remove(v.getId());
            // 封装报错
            TeamBatchPojo teamBatchPojo = new TeamBatchPojo();
            teamBatchPojo.setCode(UserTeamErrorCodeEnum.API_ERROR_271041.getCode());
            teamBatchPojo.setDataId(v.getId());
            teamBatchPojo.setErrorName(Objects.isNull(v.getSerialNo()) ? "" : v.getSerialNo());
            teamBatchPojo.setBasicOperate(userTeamOperateTagEnum.getName());
            teamBatchPojo.setFailMsg(UserTeamErrorCodeEnum.API_ERROR_271041.getMsg());
            teamBatchPojo.setFailMsgReason(UserTeamErrorCodeEnum.API_ERROR_271041.getMsg());
            return teamBatchPojo;
        }).collect(Collectors.toList());
    }
}
